home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++
- Subject: Re: MFC CArray Template
- Date: 30 Mar 1996 23:17:36 GMT
- Organization: Netcom
- Message-ID: <4jkfeg$i4b@dfw-ixnews6.ix.netcom.com>
- References: <315C1AAD.725@garlic.com>
- NNTP-Posting-Host: den-co15-25.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Sat Mar 30 5:17:36 PM CST 1996
- X-Newsreader: WinVN 0.99.7
-
- In article <315C1AAD.725@garlic.com>, grant@garlic.com says...
- >
- >In MSVC 1.52, I noticed that the CArray template uses the memcpy and
- >memmove functions rather than the contained object's assignment and copy
- >functions. Will this work for any object? I thought that doing a
- >bit-wise copy of an object wreaks havoc to the copy.
-
- And you are right (does MFC *really* do this?!?!?).
- For example, consider a string class that may either allocate from the heap or
- use an internal array for small strings:
-
- class Str {
- Str(char *s);
- private:
- char *ptr;
- char smallArray[20];
- }
-
- Str::Str(char*s) : ptr(0)
- {
- if (strlen(s)+1 > sizeof(smallArray))
- {
- ptr = new char[strlen(s)+1];
- } else {
- ptr = smallArray;
- }
- strcpy(ptr, s);
- }
-
- Clearly, a bitwise-copy of a Str in the "small" mode will fail.
-
- >What advantages are there to implementing CArray this way?
-
- 1) Speed.
- 2) Satisfaction of sadistic tendencies?
-
- IMHO, use STL or tools.h++
-
- john lilley
-
-